package Teach;

import java.io.*;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.01.18.12.32
 */
//将java源文件内容读取，并写入.txt
public class Pj4 {
    public static void main(String[] args) {
        //读取文件
        File f=new File("my.java");
        File t=new File("my.txt");
        t.delete();
        f.delete();
        if(!f.exists()){
            try {
                f.createNewFile();
                t.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try(FileInputStream fis=new FileInputStream(f)){
            byte[] buf=new byte[1024];
            int len=0;
            while ((len=fis.read(buf))>0){
                FileOutputStream fos=new FileOutputStream(t);
                fos.write(fis.read());
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        }
      
        //String f=file;
//        try(FileInputStream fis=new FileInputStream(f)){
//            byte[] buf=new byte[1024];
//            int len=0;
//            while ((len=fis.read(buf))>0){
//                FileOutputStream fos=new FileOutputStream("");
//                fos.write(fis.read());
//            }
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
    }
}
